import request from '@/utils/request'
import qs from 'qs'

const roleApi = {
  /**
   * fetchRolePageList
   * 查询分页
   *
   * @param {*} params
   */
  listPage(params) {
    return request({ url: '/role/page', method: 'get', params })
  },
  /**
   * fetchIdList
   * 根据ID查询
   * @param {*} path
   */
  findById(id) {
    return request({ url: '/role', method: 'get', params: { id } })
  },
  /**
   * addList
   * 新增
   *
   * @param {*} data
   */
  add(data) {
    return request({ url: '/role', method: 'post', data })
  },
  /**
   * uploadList
   * 修改
   * @param {*} data
   */
  edit(data) {
    return request({ url: '/role', method: 'put', data })
  },
  /**
   * updatapermission
   * 授权
   * @param {*} data
   */
  authorize(data) {
    return request({ url: '/role/permission', method: 'put', data })
  },
  /** *
   * fetchIdPermission
   * 获取权限
   * @param
   */
  getPerms(id) {
    return request({ url: '/role/' + id + '/permission', method: 'get' })
  },
  /**
   * delList
   * 批量删除
   * @param {*} params
   */
  deleteByIds(params) {
    return request({
      url: '/role',
      method: 'delete',
      params,
      paramsSerializer: params => {
        return qs.stringify(params, { indices: false })
      }
    })
  }
}

export default roleApi
